package com.mu.domain;

import okhttp3.WebSocket;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author EDY
 */
public class MessageEntity {

    private static volatile MessageEntity messageEntity;

    public static MessageEntity getSingleton(){
        if (messageEntity == null) {
            synchronized (MessageEntity.class) {
                if (messageEntity == null) {
                    messageEntity = new MessageEntity();
                    return messageEntity;
                }
            }
        }
        return messageEntity;
    }

    private final ConcurrentHashMap<WebSocket, String> userWebMap = new ConcurrentHashMap<>();
    /**
     * 对话历史存储集合
     */
    private List<RoleContent> historyList = new ArrayList<>();

    public List<RoleContent> getHistoryList() {
        return historyList;
    }

    public void setHistoryList(List<RoleContent> historyList) {
        this.historyList = historyList;
    }

    public String getUserIdByWebsocket(WebSocket webSocket){
        return userWebMap.get(webSocket);
    }

    public void setWebsocket(String userId, WebSocket webSocket){
        userWebMap.put(webSocket, userId);
    }
}
